from odoo import api, fields, models
import datetime


class ResCountryStateInheritForBasic(models.Model):
    _inherit = 'res.country.state'
    _order = 'name ASC'
    """
    重写省，屏蔽所有code的作用
    """

    code = fields.Char(string='State Code', help='The state code.', required=False)

    @api.model
    def default_get(self, fields):
        res = super(ResCountryStateInheritForBasic, self).default_get(fields)
        if self._context.get('country_id'):
            res.update({
                'country_id': self._context.get('country_id'),
            })
        return res

    def name_get(self):
        result = []
        for record in self:
            result.append((record.id, "{}".format(record.name)))
        return result
